require.def('filters',
['filter/score', 'filter/acceptratio'],
function(){
    //convert arguments to array
    var filterArgs = Array.prototype.slice.call(arguments);

    /*
     * Container for a set of filters, providing helper functions.
     */
    var FilterChain = function(filters){
        var that = this;

        /**
         * Todo this is here to simplify the get chain function. The downside is it may not
         * have finished by the time it is used... it is unlikley, but it may happen
         */
        require(['chain'], function(Chain){
            that.test = function(api, question, callbacks){
                var c = Chain.create();
                filters.forEach(function(f){
                    c.queue(f.test, [api, question], 'valid');
                });
                c.success(callbacks.valid)
                 .error(callbacks.error)
                 .exec();
            }
        });

    }

    var obj = {};

    /**
     * The pre filter chain are the filters that are run on the answer before inference is checked
     *
     * These are inexpensive and shouldn't involve a request to the api. In other words they should
     * cost (far) less than it does to run the inference
     */
    obj.getPreChain = function(){
        return new FilterChain(filterArgs.filter(function(o){ return o.isPre(); }));
    }

    /**
     * Chain of filters that are run after the answers are checked
     *
     * Should be more expensive than using inference to see if the user can answer a question
     */
    obj.getPostChain = function(){
        return new FilterChain(filterArgs.filter(function(o){ return !o.isPre(); }));
    }


    return obj;

});
